package com.example.system.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author 23050
 * @version 1.0
 * @description: TODO
 * @date 2025/1/20 22:01
 */
public class BCryptUtils {

    //将密码加密
    public static String encryptPassword(String password){
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.encode(password);
    }

    //根据数据库查出的密码得到盐值,然后加密原密码，与密文比较是否相同
    public static boolean matchesPassword(String rawPassword,String encodedPassword){
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.matches(rawPassword,encodedPassword);
    }


    public static void main(String[] args) {
        System.out.println(encryptPassword("123456"));
        System.out.println(matchesPassword("123456","$2a$10$c0AM2pJwq0BnnhBRU7BGY.2sqzMjn/MTMparKnjNgf2GX4e/q2fyW"));
    }


}
